from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

dr = webdriver.Chrome(service=Service('chromedriver.exe'))
dr.maximize_window()
dr.get('https://sahitest.com/demo/iframesTest.htm')

# 获取iframe元素
ifram = dr.find_element(By.XPATH, '/html/body/iframe')
# 进入iframe嵌套页面
dr.switch_to.frame(ifram)
time.sleep(2)
# 进入iframe页面操作元素点击
dr.find_element(By.XPATH, '/html/body/table/tbody/tr/td[1]/a[1]').click()
# 退出iframe嵌套页面(返回到默认页面)
dr.switch_to.default_content()
time.sleep(2)
dr.find_element(By.XPATH, '/html/body/input[2]').click()

time.sleep(20)
